package org.jeecg.modules.article.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.jeecg.common.aspect.annotation.Dict;
import org.jeecgframework.poi.excel.annotation.Excel;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.io.UnsupportedEncodingException;

/**
 * @Description: 文章
 * @Author: jeecg-boot
 * @Date:   2020-10-14
 * @Version: V1.0
 */
@Data
@TableName("article")
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
@ApiModel(value="article对象", description="文章")
public class Article implements Serializable {
    private static final long serialVersionUID = 1L;

	/**主键*/
	@TableId(type = IdType.ASSIGN_ID)
    @ApiModelProperty(value = "主键")
    private java.lang.String id;
	/**创建时间*/
	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
    @DateTimeFormat(pattern="yyyy-MM-dd")
    @ApiModelProperty(value = "创建时间")
    private java.util.Date createTime;
	/**标题*/
	@Excel(name = "标题", width = 15)
    @ApiModelProperty(value = "标题")
    private java.lang.String articleTitle;
	/**作者*/
	@Excel(name = "作者", width = 15)
    @ApiModelProperty(value = "作者")
    private java.lang.String articleAuthor;
	/**是否推荐到首页*/
	@Excel(name = "是否推荐到首页", width = 15, dicCode = "is_homepage")
	@Dict(dicCode = "is_homepage")
    @ApiModelProperty(value = "是否推荐到首页")
    private java.lang.Integer isHomepage;
	/**内容*/
	@Excel(name = "内容", width = 15)
    @ApiModelProperty(value = "内容")
    private java.lang.String articleContent;
	/**阅读量*/
	@Excel(name = "阅读量", width = 15)
    @ApiModelProperty(value = "阅读量")
    private java.lang.Integer articleReadingNum;
    /**文章能否评论*/
	@ApiModelProperty(value = "文章能否评论",notes = "1能评论 0不能评论 默认1")
	private java.lang.Integer articleEnableComment;

	/**是否放在轮播图中*/
    @ApiModelProperty(value = "是否放在轮播图中",notes = "0不放  1放  默认0")
    private java.lang.Integer articleTopRotation;

	/**文章所属栏目*/
	@ApiModelProperty(value = "所属栏目")
    private String articleColumn;

	@ApiModelProperty(value = "栏目置顶")
	private Integer articleColumnTop;
    @ApiModelProperty(value = "文章简介")
	private String articleIntroduction;

	/**图片*/
	@Excel(name = "图片", width = 15)
    @TableField(exist = false)
    private java.lang.String articleImageString;

    private byte[] articleImage;

    public byte[] getArticleImage(){
        if(articleImageString==null){
            return null;
        }
        try {
            return articleImageString.getBytes("UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return null;
    }

    public String getArticleImageString(){
        if(articleImage==null || articleImage.length==0){
            return "";
        }
        try {
            return new String(articleImage,"UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return "";
    }
}
